package com.example.music.controller;

import com.example.music.domain.Administrators;
import com.example.music.service.IAdministratorsService;
import com.example.music.util.AjaxResult;
import com.example.music.util.Anonymous;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Anonymous
@Api(tags = "管理员信息管理(224 魏川子)")
@RestController
@RequestMapping("/api/Administrators")
public class AdministratorsController {
    @Autowired
    private IAdministratorsService administratorsService;

    @ApiOperation(value = "获取所有管理员信息(224 魏川子)", notes = "获取所有管理员信息")
    @GetMapping("/list")
    public AjaxResult list(){
        return AjaxResult.success(administratorsService.getAdministrators());
    }

    @ApiOperation(value = "根据名字获取管理员信息(224 魏川子)", notes = "根据名字获取管理员信息")
    @GetMapping("/getAdministratorsByName/{aName}")
    public AjaxResult getAdministratorsByName(@PathVariable("aName") String aName){
        return AjaxResult.success(administratorsService.selectAdministratorsByName(aName));
    }

    @ApiOperation(value = "根据id获取管理员信息(224 魏川子)", notes = "根据id获取管理员信息")
    @GetMapping("/{id}")
    public AjaxResult getAdministratorsById(@PathVariable("id") Long id){
        return AjaxResult.success(administratorsService.selectAdministratorsById(id));
    }

    @ApiOperation(value = "新增管理员信息(224 魏川子)", notes = "新增管理员信息")
    @PostMapping("/insert")
    public AjaxResult insertAdministrators(@RequestBody Administrators administrators){
        return AjaxResult.success(administratorsService.insertAdministrators(administrators));
    }

    @ApiOperation(value = "更新管理员信息(224 魏川子)", notes = "更新管理员信息")
    @PutMapping("/update")
    public AjaxResult updateAdministrators(@Validated @RequestBody Administrators administrators){
        return AjaxResult.success(administratorsService.updateAdministrators(administrators));
    }

    @ApiOperation(value = "删除管理员信息(224 魏川子)", notes = "删除管理员信息")
    @DeleteMapping("/{id}")
    public AjaxResult deleteAdministrators(@PathVariable Long id){
        return AjaxResult.success(administratorsService.deleteAdministratorsById(id));
    }
}
